﻿using AppManager.DAL;
using AppManager.IBLL;
using AppManager.Model;
using System.Collections.Generic;
using System.Runtime.Remoting.Messaging;

namespace AppManager.BLL
{
    public class AppInfoService : BaseService<AppInfo>, IAppInfoService
    {
        public static AppInfoService Current
        {
            get
            {
                var name = typeof(AppInfoService).Name;
                var bll = CallContext.GetData(name) as AppInfoService;
                if (bll != null)
                {
                    return bll;
                }
                bll = new AppInfoService();
                CallContext.SetData(name, bll);
                return bll;
            }
        }
    }

    public class AppService : BaseService<App>, IAppService
    {
        new AppRepository dal = new AppRepository();
        public static AppService Current
        {
            get
            {
                var name = typeof(AppService).Name;
                var bll = CallContext.GetData(name) as AppService;
                if (bll != null)
                {
                    return bll;
                }
                bll = new AppService();
                CallContext.SetData(name, bll);
                return bll;
            }
        }

        public int AddOrUpdate(App app, List<AppInfo> infos)
        {
            return dal.AddOrUpdate(app, infos);
        }

        public void DeleteList(int userId, params int[] ids)
        {
            if (ids == null) return;
            foreach (var item in ids)
            {
                DeleteModel(userId, item);
            }
        }

        public void DeleteModel(int userId, int id)
        {
            var app = GetModel(s => s.Id == id);
            if (app != null)
                dal.DeleteModel(userId, app);
        }
    }

}
